package com.demo.datastructure.reorder.insertionSort;

import com.demo.datastructure.reorder.Example;

/**
 * @description: 插入排序
 * @author: ljr
 * @time: 2021/8/31 7:27
 */
public class SimpleInsertSort3 implements Example {

    @Override
    public void sort(Comparable[] a) {
       int length = a.length;
       for(int i = 0, l = i ; i < length-1; l = ++i){
            Comparable value = a[i+1];
            while (less(value, a[l])){
                a[l+1] = a[l];
                if(l-- == 0){
                    break;
                }
            }
            a[++l] = value;
       }
    }
}
